export function getErrorMessage(error: unknown): string {
    if (typeof error === 'string') return error
    if (error && typeof error === 'object') {
        const maybeError = error as { message?: unknown; toString?: () => string }
        if (typeof maybeError.message === 'string') return maybeError.message
        if (typeof maybeError.toString === 'function') return maybeError.toString()
    }
    try {
        return JSON.stringify(error)
    } catch {
        return '未知错误'
    }
}

export function isNetworkError(error: unknown): boolean {
    const message = getErrorMessage(error)
    return (
        message.includes('Network Error') ||
        message.includes('ERR_CONNECTION_REFUSED') ||
        message.includes('Failed to fetch') ||
        message.includes('NetworkError')
    )
} 